package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IGoodProductEvaluateFragmentModel;
import com.wgts.wgts.mvp.presenter.IGoodProductEvaluateFragmentPersenter;
import com.wgts.wgts.mvp.view.IGoodProductEvaluateFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.ProductEvaluateRequest;
import com.wgts.wgts.netmodle.resp.ProductEvaluateEntity;

public class GoodProductEvaluateFragmentPersenter implements IGoodProductEvaluateFragmentPersenter {

    private IGoodProductEvaluateFragmentModel model;

    private IGoodProductEvaluateFragmentView view;

    private int pageIndex = 1 ;

    private int pageSize = 20;

    private String id;

    public GoodProductEvaluateFragmentPersenter(IGoodProductEvaluateFragmentModel model, IGoodProductEvaluateFragmentView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void productEvaluate() {
        ProductEvaluateRequest request = new ProductEvaluateRequest();
        request.productId = id;
        request.pageIndex = String.valueOf(pageIndex);
        request.pageSize = String.valueOf(pageSize);
        model.productEvaluate(request, new HttpResultSubscriber<ProductEvaluateEntity>() {
            @Override
            public void onSuccess(ProductEvaluateEntity evaluateEntity) {

                if(evaluateEntity.list.size() < pageSize){
                    view.evaluateResult(evaluateEntity, true);
                }else{
                    view.evaluateResult(evaluateEntity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void initProductEvaluate(String id) {
        pageIndex = 1;
        this.id = id;
        ProductEvaluateRequest request = new ProductEvaluateRequest();
        request.productId = id;
        request.pageIndex = String.valueOf(pageIndex);
        request.pageSize = String.valueOf(pageSize);
        model.productEvaluate(request, new HttpResultSubscriber<ProductEvaluateEntity>() {
            @Override
            public void onSuccess(ProductEvaluateEntity evaluateEntity) {
                if(evaluateEntity.list.size() < pageSize){
                    view.initEvaluateResult(evaluateEntity, true);
                }else{
                    view.initEvaluateResult(evaluateEntity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
